package com.cpecc.dao.wuzi;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.system.User;
import com.cpecc.model.wuzi.WeiXiu;
import com.cpecc.model.wuzi.WeiXiuJL;

@Repository
public class WeiXiuJLDao {
	
	@Resource
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public void save(WeiXiuJL weiXiuJL){
		Session session=sessionFactory.getCurrentSession();
		session.save(weiXiuJL);
		session.flush();
	}
	
	@SuppressWarnings("unchecked")
	public List<WeiXiuJL> getAllJL(String weiXiuId){
		String hql="from WeiXiuJL t where t.weiXiu.id=? order by t.caoZuoRQ desc";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, weiXiuId);
		return query.list();
	}
	
	@SuppressWarnings("unchecked")
	public List<WeiXiu> getMySPJL(User user){
		String hql="select t.weiXiu from WeiXiuJL t where t.user.id=? group by t.weiXiu order by t.weiXiu.shenQingRQ desc";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, user.getId());
		return query.list();
	}
}
